using Abp.IdentityServer4;
using Abp.Zero.EntityFrameworkCore;
using L._52ABP.Common.Consts;
using Microsoft.EntityFrameworkCore;
using Yozeev.Authorization.Roles;
using Yozeev.BusinessLogic;
using Yozeev.DataFileObjects;
using Yozeev.Editions;
using Yozeev.EntityMapper.AccountDetails;
using Yozeev.EntityMapper.Accounts;
using Yozeev.EntityMapper.ActivityDetails;
using Yozeev.EntityMapper.Activitys;
using Yozeev.EntityMapper.ActivityTempDetails;
using Yozeev.EntityMapper.ActivityTemps;
using Yozeev.EntityMapper.Boats;
using Yozeev.EntityMapper.Books;
using Yozeev.EntityMapper.Branchs;
using Yozeev.EntityMapper.BranchUsers;
using Yozeev.EntityMapper.CheckRecords;
using Yozeev.EntityMapper.ClientVersions;
using Yozeev.EntityMapper.CommonCustomers;
using Yozeev.EntityMapper.Customers;
using Yozeev.EntityMapper.DataFileObjects;
using Yozeev.EntityMapper.DateDictionarys;
using Yozeev.EntityMapper.Devices;
using Yozeev.EntityMapper.GateRecords;
using Yozeev.EntityMapper.Menus;
using Yozeev.EntityMapper.MultiTenancy;
using Yozeev.EntityMapper.PayMethods;
using Yozeev.EntityMapper.PowerRoles;
using Yozeev.EntityMapper.Powers;
using Yozeev.EntityMapper.PriceAudits;
using Yozeev.EntityMapper.PrintStyleChilds;
using Yozeev.EntityMapper.PrintStyles;
using Yozeev.EntityMapper.RechargeRecords;
using Yozeev.EntityMapper.Routes;
using Yozeev.EntityMapper.ScenicSpots;
using Yozeev.EntityMapper.Schedules;
using Yozeev.EntityMapper.Sources;
using Yozeev.EntityMapper.SubscriptionPayments;
using Yozeev.EntityMapper.TicketDetailHistorys;
using Yozeev.EntityMapper.TicketDetails;
using Yozeev.EntityMapper.TicketIntroduces;
using Yozeev.EntityMapper.TicketPrices;
using Yozeev.EntityMapper.TicketRoles;
using Yozeev.EntityMapper.Tickets;
using Yozeev.EntityMapper.TicketScheduleEnables;
using Yozeev.EntityMapper.TicketStationEnables;
using Yozeev.EntityMapper.TicketStations;
using Yozeev.EntityMapper.TicketUserEnables;
using Yozeev.EntityMapper.TravelAgencys;
using Yozeev.EntityMapper.TravelTicketDetails;
using Yozeev.EntityMapper.UserManagerment.Users;
using Yozeev.EntityMapper.VerifiableSets;
using Yozeev.EntityMapper.WechatManagement.WechatAppConfigs;
using Yozeev.EntityMapper.Wharfs;
using Yozeev.MultiTenancy;
using Yozeev.MultiTenancy.Payments;
using Yozeev.PhoneBooks.Books;
using Yozeev.PhoneBooks.Persons;
using Yozeev.SystemConfig;
using Yozeev.SystemConfig.BasicConfig;
using Yozeev.SystemConfig.SystemRecord;
using Yozeev.UserManagerment.Users;
using Yozeev.WechatManagement.WechatAppConfigs;

namespace Yozeev.EntityFrameworkCore
{
    public class YozeevDbContext : AbpZeroDbContext<Tenant, Role, User, YozeevDbContext>, IAbpPersistedGrantDbContext
    {
        /* Define a DbSet for each entity of the application */

        #region 测试

        public virtual DbSet<Person> People { get; set; }

        public virtual DbSet<Book> Books { get; set; }

        #endregion


        #region 二进制数据

        public virtual DbSet<DataFileObject> DataFileObjects { get; set; }

        #endregion


        #region 订阅

        public virtual DbSet<SubscribableEdition> SubscribableEditions { get; set; }

        public virtual DbSet<SubscriptionPayment> SubscriptionPayments { get; set; }

        #endregion


        #region IdentityServer4

        public virtual DbSet<PersistedGrantEntity> PersistedGrants { get; set; }

        #endregion


        #region 微信

        public virtual DbSet<WechatAppConfig> WechatAppConfigs { get; set; }

        #endregion




        public YozeevDbContext(DbContextOptions<YozeevDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //修改ABP的默认表信息
            modelBuilder.ChangeAbpTablePrefix<Tenant, Role, User>(string.Empty, AbpProEFCoreConsts.SchemaNames.ABP);
            base.OnModelCreating(modelBuilder);


            // ============  其它对表信息的修改 ============= 

            modelBuilder.ApplyConfiguration(new UserCfg());
            modelBuilder.ApplyConfiguration(new SubscriptionPaymentCfg());
            modelBuilder.ApplyConfiguration(new DataFileObjectCfg());
            modelBuilder.ApplyConfiguration(new TenantCfg());

            // ==================== identityServer4 ================================
            modelBuilder.ConfigurePersistedGrantEntity(string.Empty, AbpProEFCoreConsts.SchemaNames.ABP);

            // ==================== Wechat ================================
            modelBuilder.ApplyConfiguration(new WechatAppConfigCfg());
            // ==================== DemoBook ================================
            modelBuilder.ApplyConfiguration(new BookCfg());


            #region SystemConfig
            modelBuilder.ApplyConfiguration(new PayMethodCfg());
            modelBuilder.ApplyConfiguration(new DateDictionaryCfg());
            modelBuilder.ApplyConfiguration(new CheckRecordCfg());
            modelBuilder.ApplyConfiguration(new BranchCfg());
            modelBuilder.ApplyConfiguration(new BranchUserCfg());
            modelBuilder.ApplyConfiguration(new ClientVersionCfg());
            #endregion

            #region BusinessLogic
            //Boat
            modelBuilder.ApplyConfiguration(new BoatCfg());
            modelBuilder.ApplyConfiguration(new RouteCfg());
            modelBuilder.ApplyConfiguration(new ScheduleCfg());
            modelBuilder.ApplyConfiguration(new WharfCfg());
            //Device
            modelBuilder.ApplyConfiguration(new DeviceCfg());
            modelBuilder.ApplyConfiguration(new GateRecordCfg());
            modelBuilder.ApplyConfiguration(new VerifiableSetCfg());
            //common
            modelBuilder.ApplyConfiguration(new CustomerCfg());
            modelBuilder.ApplyConfiguration(new ScenicSpotCfg());
            modelBuilder.ApplyConfiguration(new SourceCfg());
            modelBuilder.ApplyConfiguration(new CommonCustomerCfg());
            //Ticket
            modelBuilder.ApplyConfiguration(new AccountCfg());
            modelBuilder.ApplyConfiguration(new AccountDetailCfg());
            modelBuilder.ApplyConfiguration(new ActivityCfg());
            modelBuilder.ApplyConfiguration(new ActivityDetailCfg());
            modelBuilder.ApplyConfiguration(new ActivityTempCfg());
            modelBuilder.ApplyConfiguration(new ActivityTempDetailCfg());
            modelBuilder.ApplyConfiguration(new PriceAuditCfg());
            modelBuilder.ApplyConfiguration(new TicketCfg());
            modelBuilder.ApplyConfiguration(new TicketDetailCfg());
            modelBuilder.ApplyConfiguration(new TicketDetailHistoryCfg());
            modelBuilder.ApplyConfiguration(new TicketIntroduceCfg());
            modelBuilder.ApplyConfiguration(new TicketPriceCfg());
            modelBuilder.ApplyConfiguration(new TicketStationCfg());
            modelBuilder.ApplyConfiguration(new TicketStationEnableCfg());
            modelBuilder.ApplyConfiguration(new TicketUserEnableCfg());
            modelBuilder.ApplyConfiguration(new TicketScheduleEnableCfg());
            modelBuilder.ApplyConfiguration(new TicketRoleCfg());
            //Travel
            modelBuilder.ApplyConfiguration(new RechargeRecordCfg());
            modelBuilder.ApplyConfiguration(new TravelAgencyCfg());
            modelBuilder.ApplyConfiguration(new TravelTicketDetailCfg());
            //Power
            modelBuilder.ApplyConfiguration(new MenuCfg());
            modelBuilder.ApplyConfiguration(new PowerCfg());
            modelBuilder.ApplyConfiguration(new PowerRoleCfg());
            //Print
            modelBuilder.ApplyConfiguration(new PrintStyleCfg());
            modelBuilder.ApplyConfiguration(new PrintStyleChildCfg());
            #endregion
        }

        #region SystemConfig
        public virtual DbSet<PayMethod> PayMethods { get; set; }
        public virtual DbSet<DateDictionary> DateDictionarys { get; set; }
        public virtual DbSet<CheckRecord> CheckRecords { get; set; }
        public virtual DbSet<Branch> Branchs { get; set; }
        public virtual DbSet<BranchUser> BranchUsers { get; set; }
        public virtual DbSet<ClientVersion> ClientVersions { get; set; }

        #endregion

        #region BusinessLogic
        //Boat
        public virtual DbSet<Boat> Boats { get; set; }
        public virtual DbSet<Route> Routes { get; set; }
        public virtual DbSet<Schedule> Schedules { get; set; }
        public virtual DbSet<Wharf> Wharves { get; set; }

        //Device
        public virtual DbSet<Device> Devices { get; set; }
        public virtual DbSet<GateRecord> GateRecords { get; set; }
        public virtual DbSet<VerifiableSet> VerifiableSets { get; set; }
        //common
        public virtual DbSet<Customer> Customers { get; set; }
        public virtual DbSet<ScenicSpot> ScenicSpots { get; set; }
        public virtual DbSet<Source> Sources { get; set; }
        public virtual DbSet<CommonCustomer> CommonCustomers { get; set; }
        //Ticket
        public virtual DbSet<Account> Accounts { get; set; }
        public virtual DbSet<AccountDetail> AccountDetails { get; set; }
        public virtual DbSet<Activity> Activities { get; set; }
        public virtual DbSet<ActivityDetail> ActivityDetails { get; set; }
        public virtual DbSet<ActivityTemp> ActivityTemps { get; set; }
        public virtual DbSet<ActivityTempDetail> ActivityTempDetails { get; set; }
        public virtual DbSet<PriceAudit> PriceAudits { get; set; }
        public virtual DbSet<Ticket> Tickets { get; set; }
        public virtual DbSet<TicketDetail> TicketDetails { get; set; }
        public virtual DbSet<TicketDetailHistory> TicketDetailHistorys { get; set; }
        public virtual DbSet<TicketIntroduce> TicketIntroduces { get; set; }
        public virtual DbSet<TicketPrice> TicketPrice { get; set; }
        public virtual DbSet<TicketStation> TicketStations { get; set; }
        public virtual DbSet<TicketStationEnable> TicketStationEnables { get; set; }
        public virtual DbSet<TicketUserEnable> TicketUserEnables { get; set; }
        public virtual DbSet<TicketScheduleEnable> TicketScheduleEnables { get; set; }
        public virtual DbSet<TicketRole> TicketRoles { get; set; }
        //Travel
        public virtual DbSet<RechargeRecord> RechargeRecords { get; set; }
        public virtual DbSet<TravelAgency> TravelAgencys { get; set; }
        public virtual DbSet<TravelTicketDetail> TravelTicketDetails { get; set; }
        //Power
        public virtual DbSet<Menu> Menus { get; set; }
        public virtual DbSet<Power> Powers { get; set; }
        public virtual DbSet<PowerRole> PowerRoles { get; set; }

        //Print
        public virtual DbSet<PrintStyle> PrintStyles { get; set; }
        public virtual DbSet<PrintStyleChild> PrintStyleChilds { get; set; }

        #endregion

    }
}